package com.study.register.dao;

import com.study.common.BaseDao.BaseDaoImpl;
import com.study.common.entity.User;
import com.study.main.entity.Information;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
 * @Date 2018/8/31 15:26
 * @Description
 */
@Repository(value = "registerDao")
public class RegisterDaoImpl extends BaseDaoImpl implements RegisterDao {
    @Override
    public void updateByPassword(User user) {
        Session s = getSession();
        String hql = "update User set passWord = ? where telNumber = ?";
        Query q = s.createQuery(hql);
        q.setParameter(0,user.getPassWord());
        q.setParameter(1,user.getTelNumber());
        q.executeUpdate();
    }

    @Override
    public User findByTelNumber(String telNumber) {
        Session s = getSession();
        String hql = "from User where telNumber = ?";
        Query q = s.createQuery(hql);
        q.setParameter(0,telNumber);
        return (User)q.uniqueResult();
    }

    @Override
    public User findByUserName(String userName) {
        Session s = getSession();
        String hql = "from User  where userName = ?";
        Query q = s.createQuery(hql);
        q.setParameter(0,userName);
        return (User)q.uniqueResult();
    }
}
